<?php
header('Content-type:text/html;charset=utf8');
/**
 * xysc users Version1.0
 * ==================================
 * Copy 2016-2017
 * Web:www.xjh7.com
 * ==================================
 * Author:xjh
 * Date:2016-4-27
*/
/**
 * 
 * 标签控制器
 * @author xjh
 *
 */
class TagController extends Controller{
	/**
	 * 访问控制过滤
	 * @author xjh
	 */
	function filters(){
		return array(
			'accessControl'
		);
	}
	/**
	 * 具体方法访问具体条件
	 */
	
	function accessRules(){
		return array(
			array(
				'allow',
				'actions'=>array(''),
				'users'=>array('@'),//登陆系统的用户
			),
//			array(
//				'deny',
//				'users'=>array('*'),//所有用户
//			),
		);
	}

	/**
	 * 顶部信息
	 * 
	 */
	function actionsearchTagTop(){
		$this->renderPartial('searchtagTop');
	}

	/**
	 * 导航删除
	 */
	function actionTagDel($tag_id){
		$tag_model = Tag::model();
		$row = $tag_model->TagDel($tag_id);
		if($row){
			echo 1;
			exit;
		}else{
			echo 0;
			exit;
		}
	}

	/**
	 * 标签修改
	 */
	function actionTagUpd($tag_id){
		$tag_model = new Tag();
		$tag_info = $tag_model->getTagById($tag_id);
		if(isset($_POST) && @$_POST['send'] == "修改"){
			$row = $tag_model->TagUpdate($_POST,$tag_id);
			if($row){
				$this->redirect("./index.php?r=backweb/tag/tag");
			}else{
				echo "<script>alert('修改失败');</script>";
			}
		}
		$this->renderPartial('updatetag',array('tag_info'=>$tag_info[0]));
	}
	
	
	/**
	 * 是否有效的切换
	 */
	function actionActive($tag_id,$active_id){
		$active = new active();
		$active -> setActive($tag_id,$active_id,"tag","tag_id");
		$this->redirect("./index.php?r=backweb/tag/tag");
	}
	
	/**
	 *标签控制器
	 * @author xjh
	 */
	function actiontag(){
		$tag_model = Tag::model();
		$nav_model = Nav::model();
		if(@$_POST['send'] == '更新信息'){
			for ($i=0; $i < count($_POST['tag_id']); $i++) { 
				$row = $tag_model -> updateTag($_POST['tag_id'][$i],$_POST['sort'][$i]);
			}
		}
		if(@$_POST['btquery'] == '查询'){
			$infos = $tag_model->pageSearch($_POST);
		}else{
			$infos = $tag_model->all();
		}
		$page_list = $nav_model->page_list;
		$infos_count = $nav_model->infos_count;
		$active = array(
			0=>'否',
			1=>'是',
		);
		$obj = new CDbConnection();
		$topInfo = $obj -> getStats();
		
		$number = $topInfo[0];
		$times = $topInfo[1];
		$this->renderPartial('tag',array('infos'=>$infos,'active'=>$active,'info_count'=>$infos_count[0]['count(*)'],'page_list'=>$page_list,'number'=>$number,'times'=>$times));
	}
	
	function actiontoAddTag(){
		$tag_model = new Tag();
		$this->renderPartial('tagadd');
	}
	/*
	 * 导航添加控制器
	 * @author xjh
	 */
	function actionAddTag(){
		$tag_model = new Tag();
		$infos = $tag_model->checkExist($_POST);
			if($_POST['btsave'] == '添加'){
				if(!empty($infos)){
					echo "<script>alert('标签已存在');window.history.back();</script>";
				}else{
					if($tag_model->addTag($_POST)){
						echo "<script>alert('标签添加成功');</script>";
						 $this->renderPartial('searchTagTop');
					}else{
						echo "<script>alert('添加失败');</script>";
					}
				}
			}else{
				echo "非法操作,请返回继续操作";
				exit;
			}
		
	}
}
?>